home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 1 / PCU0103CD1.iso / entertn / demos / files / aomtrial.exe / AOM / AI / SCN27P6.XS < prev    next >
Encoding:
Text File  |  2002-07-22  |  7.5 KB  |  205 lines

  1. //==============================================================================
  2. // Scn27p6: AI Scenario Script for scenario 27 player 6
  3. //==============================================================================
  4. /*
  5.    AI owner:  Dave Leary
  6.    Scenario owner: Joe "The Golem" Gillum
  7.  
  8.    Overview: Very basic AI script to handle the units (giants) that spawn
  9.     in the channels to the west and east. It also handles the big "giant pushes"
  10.     at the end of the scenario.
  11.     
  12.     The early giant attacks as the player first moves up the pass are handled 
  13.     with triggers.
  14.  
  15.    This AI simply takes all units that are spawned and moves them to the 
  16.     player's town center.  Pacing and size of attacks are controlled by the
  17.     scenario designer via trigger.
  18.  
  19. */
  20. //==============================================================================
  21. include "scn lib.xs";
  22.  
  23. // Used to search for spawned CP military units
  24. int westStartQuery = -1;
  25. int eastStartQuery = -1;
  26.  
  27. int westFinalStartQuery = -1;
  28. int eastFinalStartQuery = -1;
  29. int southFinalStartQuery = -1;
  30.  
  31. //==============================================================================
  32. // Set Town Location
  33. //==============================================================================
  34. void setTownLocation(void)
  35. {
  36.    //Look for the "Town Location" marker.
  37.    kbSetTownLocation(kbGetBlockPosition("3989"));
  38. }
  39.  
  40. //==============================================================================
  41. // miscStartup
  42. //==============================================================================
  43. void miscStartup(void)
  44. {
  45.    //Startup message(s).
  46.    aiEcho("");
  47.    aiEcho("");
  48.    aiEcho("Scn27P2 AI Start, filename='"+cFilename+"'.");
  49.    //Spit out the map size.
  50.    aiEcho("  Map size is ("+kbGetMapXSize()+", "+kbGetMapZSize()+").");
  51.    //Cheat like a bastard.  Once only, though.
  52.    kbLookAtAllUnitsOnMap();
  53.    //Calculate some areas.
  54.    kbAreaCalculate(1200.0);
  55.    //Set our town location.
  56.    setTownLocation();
  57.     //Reset random seeds
  58.     aiRandSetSeed();
  59.    //Allocate all resources
  60.    kbEscrowAllocateCurrentResources();
  61. }
  62.  
  63. //==============================================================================
  64. // FUNCTIONS
  65. //==============================================================================
  66. void launchAttack(vector start=vector(-1,-1,-1), int query=-1, int count=-1)
  67. {
  68.    int attackID = aiPlanCreate("Attack at "+(xsGetTime()/1000), cPlanAttack);
  69.  
  70.    if (attackID < 0)
  71.       return;
  72.  
  73.    // Attack player #1.
  74.     if (aiPlanSetVariableInt(attackID, cAttackPlanPlayerID, 0, 1) == false)
  75.       return;
  76.  
  77.    aiPlanSetVariableVector(attackID, cAttackPlanGatherPoint, 0, start);
  78.    aiPlanSetVariableFloat(attackID, cAttackPlanGatherDistance, 0, 50.0);
  79.    aiPlanSetInitialPosition( attackID, start);
  80.    aiPlanAddUnitType(attackID, cUnitTypeMythUnit, 1, count, count);
  81.  
  82.     aiPlanSetNumberVariableValues(attackID, cAttackPlanTargetTypeID, 2, true);
  83.  
  84.     //Target unit types to attack 
  85.     aiPlanSetVariableInt(attackID, cAttackPlanTargetTypeID, 0, cUnitTypeBuilding);
  86.     aiPlanSetVariableInt(attackID, cAttackPlanTargetTypeID, 1, cUnitTypeUnit);
  87.    
  88.     // Needs all units listed - get 'em all!
  89.    aiPlanSetRequiresAllNeedUnits(attackID, true);
  90.    aiPlanSetActive(attackID);
  91. }
  92.  
  93. // MAIN SPAWN GIANTS AI FUNC - called via trigger when an army is available in one of the channels.
  94. // ChannelID indicates which channel has the units.
  95. void spawnGiants(int channelID=-1)
  96. {
  97.     // Locations for spawning fun
  98.     vector spawnLocationWest=kbGetBlockPosition("1571350");
  99.     vector spawnLocationEast=kbGetBlockPosition("1571349");
  100.     
  101.     vector spawnLocationWestFinal=kbGetBlockPosition("1571802");
  102.     vector spawnLocationSouthFinal=kbGetBlockPosition("1571803");
  103.     vector spawnLocationEastFinal=kbGetBlockPosition("1571804");
  104.  
  105.    int targetCount = -1;
  106.  
  107.    aiEcho("Spawn Giants firing, channelID = "+channelID);
  108.    switch(channelID)
  109.    {
  110.         case 0:
  111.       {
  112.          //check west
  113.          targetCount = getUnassignedUnitCount(spawnLocationWest, 50.0, 6, cUnitTypeMythUnit);
  114.          aiEcho("Found "+targetCount+" myth units in the west channel.");
  115.          if (targetCount > 0)
  116.          {
  117.             launchAttack(spawnLocationWest, westStartQuery, targetCount);
  118.          }
  119.             break;
  120.       }
  121.         case 1:
  122.       {
  123.          //check east
  124.          targetCount = getUnassignedUnitCount(spawnLocationEast, 50.0, 6, cUnitTypeMythUnit);
  125.          aiEcho("Found "+targetCount+" myth units in the east channel.");
  126.          if (targetCount > 0)
  127.          {
  128.             launchAttack(spawnLocationEast, eastStartQuery, targetCount);
  129.          }
  130.          break;
  131.       }
  132.         case 2:
  133.         {
  134.             //west final version
  135.          targetCount = getUnassignedUnitCount(spawnLocationWestFinal, 50.0, 6, cUnitTypeMythUnit);
  136.          aiEcho("Found "+targetCount+" myth units in the west (final) channel.");
  137.          if (targetCount > 0)
  138.          {
  139.             launchAttack(spawnLocationWestFinal, westFinalStartQuery, targetCount);
  140.          }
  141.             break;
  142.         }
  143.         case 3:
  144.         {
  145.             //south final version
  146.          targetCount = getUnassignedUnitCount(spawnLocationSouthFinal, 50.0, 6, cUnitTypeMythUnit);
  147.          aiEcho("Found "+targetCount+" myth units in the south (final) channel.");
  148.          if (targetCount > 0)
  149.          {
  150.             launchAttack(spawnLocationSouthFinal, southFinalStartQuery, targetCount);
  151.          }
  152.          break;
  153.         }
  154.  
  155.         case 4:
  156.         {
  157.             //east final version
  158.          targetCount = getUnassignedUnitCount(spawnLocationEastFinal, 50.0, 6, cUnitTypeMythUnit);
  159.          aiEcho("Found "+targetCount+" myth units in the east (final) channel.");
  160.          if (targetCount > 0)
  161.          {
  162.             launchAttack(spawnLocationEastFinal, eastFinalStartQuery, targetCount);
  163.          }
  164.          break;
  165.         }
  166.    }
  167. }
  168.  
  169. //==============================================================================
  170. // MAIN.
  171. //==============================================================================
  172. void main(void)
  173. {
  174.     // Locations for spawning fun
  175.     vector spawnLocationWest=kbGetBlockPosition("1571350");
  176.     vector spawnLocationEast=kbGetBlockPosition("1571349");
  177.  
  178.     vector spawnLocationWestFinal=kbGetBlockPosition("1571802");
  179.     vector spawnLocationSouthFinal=kbGetBlockPosition("1571803");
  180.     vector spawnLocationEastFinal=kbGetBlockPosition("1571804");
  181.  
  182.  
  183.     miscStartup();
  184.  
  185.     // Set up the two queries.
  186.     westStartQuery = kbUnitQueryCreate("checkWestStart");    // Look for CP units
  187.    if ( configQuery(westStartQuery, cUnitTypeMythUnit, -1, cUnitStateAlive, 2, spawnLocationWest, true, 30) == false)
  188.       aiEcho("Query failed");
  189.  
  190.    eastStartQuery = kbUnitQueryCreate("checkEastStart");    // Look for CP units
  191.    if ( configQuery(eastStartQuery, cUnitTypeMythUnit, -1, cUnitStateAlive, 2, spawnLocationEast, true, 30) == false)
  192.       aiEcho("Query failed");
  193.  
  194.     westFinalStartQuery = kbUnitQueryCreate("checkWestFinalStart");  // Look for CP units
  195.    if ( configQuery(westFinalStartQuery, cUnitTypeMythUnit, -1, cUnitStateAlive, 2, spawnLocationWestFinal, true, 30) == false)
  196.       aiEcho("Query failed");
  197.  
  198.     eastFinalStartQuery = kbUnitQueryCreate("checkEastFinalStart");  // Look for CP units
  199.    if ( configQuery(eastFinalStartQuery, cUnitTypeMythUnit, -1, cUnitStateAlive, 2, spawnLocationEastFinal, true, 30) == false)
  200.       aiEcho("Query failed");
  201.  
  202.     southFinalStartQuery = kbUnitQueryCreate("checkSouthFinalStart");  // Look for CP units
  203.    if ( configQuery(southFinalStartQuery, cUnitTypeMythUnit, -1, cUnitStateAlive, 2, spawnLocationSouthFinal, true, 30) == false)
  204.       aiEcho("Query failed");
  205. }